package com.example.wanandroid.service.impl;

import com.example.wanandroid.mapper.ViewMapper;
import com.example.wanandroid.service.ViewService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Desc TODO
 * @Date 2020/4/19 12:45
 */
@Service
public class ViewServiceImpl implements ViewService {
    @Autowired
    ViewMapper viewMapper;

    @Override
    public PageInfo<HashMap<String, Object>> getAllQuestions(int page, int pageSize) {
        //设置分页信息
        PageHelper.startPage(page, pageSize);
        List<HashMap<String, Object>> mapList = viewMapper.getAllQuestions();
        //获取分页信息
        PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<>(mapList);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getQuestionsByUserId(long userId, int page, int pageSize) {
        //设置分页信息
        PageHelper.startPage(page, pageSize);
        List<HashMap<String, Object>> mapList = viewMapper.getQuestionsByUserId(userId);
        //获取分页信息
        PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<>(mapList);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getAnswersByUserId(long userId, int page, int pageSize) {
        //设置分页信息
        PageHelper.startPage(page, pageSize);
        List<HashMap<String, Object>> mapList = viewMapper.getAnswersByUserId(userId);
        //获取分页信息
        PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<>(mapList);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getAnswersByQuestionId(long questionId, int page, int pageSize) {
        //设置分页信息
        PageHelper.startPage(page, pageSize);
        List<HashMap<String, Object>> mapList = viewMapper.getAnswersByQuestionId(questionId);
        //获取分页信息
        PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<>(mapList);
        return pageInfo;
    }

    @Override
    public HashMap<String, Object> getQuestionById(long questionId) {
        return viewMapper.getQuestionById(questionId);
    }
}
